ifeq ($(strip $(SUPRA_PATH)),)
$(error "%SUPRA_PATH% no find!")
endif
_SUPRA_PATH := $(subst \,/,$(SUPRA_PATH))

PROGRAM_BIN := build_flash/main.bin
PROGRAM_BIN_SIZE := $(shell stat --format=%s $(PROGRAM_BIN))

OPENOCD_CMD :=	$(_SUPRA_PATH)/openocd/bin/openocd_cmd.bat
OPENOCD 	:=	$(_SUPRA_PATH)/openocd/bin/openocd.exe
WRITE_PRG_CMD := \
	-c "variable ADAPTER cmsis-dap; \
	variable CONNECT_UNDER_RESET 1" -c "variable ADAPTER_SPEED 1200" \
	-f $(_SUPRA_PATH)/pio/agrv2k.cfg \
	-c "agrv progress 0" -c "reset init" \
	-c "reset init; flash probe 0" \
	-c "flash erase_address pad 0x80000000 $(PROGRAM_BIN_SIZE)" \
	-c "flash write_image $(PROGRAM_BIN) 0x80000000" \
	-c "reset run" \
	-c exit

program:
	$(OPENOCD_CMD) $(WRITE_PRG_CMD)